package cn.tedu.egbank.customer.controller;

import cn.tedu.egbank.base.response.JsonResult;
import cn.tedu.egbank.customer.mapper.CustomerMapper;
import cn.tedu.egbank.customer.pojo.dto.AddCustomerParam;
import cn.tedu.egbank.customer.pojo.entity.Customer;
import cn.tedu.egbank.customer.pojo.vo.AllOfCustomerVO;
import cn.tedu.egbank.customer.pojo.vo.CustomerVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;

@Slf4j
@RestController
@Tag(name = "01-客户模块", description = "10")
@RequestMapping("/api/customer/")
public class CustomerController {
    @Autowired
    private CustomerMapper customerMapper;

    @PostMapping("add")
    @Operation(summary = "注册新用户")
    @ApiOperationSupport(order = 10)
    public JsonResult addCustomer(@RequestBody AddCustomerParam addCustomerParam){
        log.debug("addCustomerParam=" + addCustomerParam);
        Customer customer = new Customer();
        BeanUtils.copyProperties(addCustomerParam, customer);
        customer.setCreatedAt(new Date());
        int rows = customerMapper.insertCustomer(customer);
        CustomerVO customerVO = customerMapper.selectNewCustomer(customer);
        return JsonResult.ok(customerVO);
    }

    @GetMapping("list")
    @Operation(summary = "获取所有客户的信息")
    @ApiOperationSupport(order = 20)
    public JsonResult list(){
        ArrayList<CustomerVO> customers = customerMapper.selectAll();
        return JsonResult.ok(customers);
    }

    @GetMapping("{CustomerId}")
    @Operation(summary = "获取指定客户信息")
    @ApiOperationSupport(order = 30)
    public JsonResult getAll(@PathVariable("CustomerId") Integer CustomerId){
        AllOfCustomerVO  customerVO = customerMapper.selectById(CustomerId);
        return JsonResult.ok(customerVO);
    }







}








































